const WXAPI = require('../../utils/main');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    countdown:{
      day: '',
      hour: '',
      minute: '',
      second: ''
    },
    tag: ['家', '公司','学校','其他'],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.countDown();
    that.stay_payment()
  },
  //倒计时
  countDown:function() {
    var that = this
    var starttime = '2019/07/30 09:04:19'
    var start = new Date(starttime.replace(/-/g, "/")).getTime()
    console.log(start)
    var endTime = start + 15 * 60000
    console.log(endTime)
    var date = new Date(); //现在时间
    var now = date.getTime(); //现在时间戳
    console.log(now)
    var allTime = endTime - now
    console.log(allTime)
    var m, s;
    if (allTime > 0) {
      m = Math.floor(allTime / 1000 / 60 % 60);
      s = Math.floor(allTime / 1000 % 60);
      that.setData({
        countdown: m + "：" + s,
      })
      setTimeout(that.countDown, 1000);
    } else {
      console.log('已截止')
      that.setData({
        countdown: '00:00'
      })
    }
  },
  stay_payment:function(){
    WXAPI.commodity_order({  
      _uid:wx.getStorageSync('uid'),
      _do:'select',
      _status:9
    }).then(function (res) {
        console.log(res)
    }).catch(function (e) {
      wx.hideLoading()
      console.log(e)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    // wx.reLaunch({
    //   url: '../shopcart/shopcart'
    // })
    var that = this

    if(getCurrentPages().length > 2) {
      //获取页面栈
      let pages = getCurrentPages()
      //给上一个页面设置状态
      let curPage = pages[pages.length - 2];
      let data = curPage.data;
      curPage.setData({'isBack': true});
    }

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})